import { InjectableObject } from "../../inject";
import PresenterMvpProxy, { IPresenterProxy } from "../proxy/presenter/PresenterMvpProxy";
import { IBaseView } from "./IBaseView";

export abstract class BasePresenter<V extends IBaseView> extends InjectableObject {
    private _view: V = null;
    private _proxy: IPresenterProxy = null;

    public attach(view: V) {

        this._view = view;

        this.getMvpProxy().injectModels();

        this.onAttach();
    }

    public detach() {
        this._view = null;

        this.getMvpProxy().detachModels();

        this.onDetach();
    }

    protected getView(): V {
        return this._view;
    }

    private getMvpProxy() {
        if (null === this._proxy) {
            this._proxy = new PresenterMvpProxy(this);
        }

        return this._proxy;
    }

    abstract onAttach(): void;
    abstract onDetach(): void;
}
